#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Create by zhang
# Create on 2023-03-02 19:37
from typing import List

from pandas import DataFrame

from core.dataClasses import StockTradeDataColumnName


def stock_trade_dataframe_data_assembler(source_df: DataFrame, source_column_name: StockTradeDataColumnName, target_column_name: StockTradeDataColumnName) -> DataFrame:
    """
    股票交易数据（DataFrame格式）字段转换器
    :param source_df: 源数据
    :param source_column_name: 源字段
    :param target_column_name: 目标字段
    :return: 转换字段后的股票交易数据（DataFrame格式）
    """
    if source_df is None or source_df.empty:
        return None
    source_column_name_keys: List[str] = list(source_column_name.__dict__.keys())
    target_column_name_keys: List[str] = list(target_column_name.__dict__.keys())
    column_dict = {}
    if source_column_name_keys and len(source_column_name_keys) > 0:
        for key in source_column_name_keys:
            column_dict[source_column_name.__getattribute__(key)] = target_column_name.__getattribute__(key)
        source_df.rename(columns=column_dict)
    return source_df